<template>
	<!-- 农户申请 -->
	<view class="box">
		<u-form :model="form" ref="uForm">
			<u-form-item label="类别" label-width="200">
				<u-radio-group v-model="type">
					<u-radio v-for="(item, index) in typeList" :key="index" :name="item.name" :disabled="item.disabled">
						{{ item.name }}
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="单位/个人名称" label-width="200"><u-input v-model="form.name" /></u-form-item>
			<u-form-item label="联系电话" label-width="200"><u-input v-model="form.phone" /></u-form-item>
			<u-form-item label='地址' label-width="200">
				<u-input v-model="form.address" disabled @click="showAddress=true"/>
				<u-picker mode="region" v-model="showAddress" :area-code='["13", "1303", "130304"]' @confirm="addressSelect"></u-picker>
			</u-form-item>
			<u-form-item label="详细地址" label-width="200"><u-input v-model="form.address_desc" /></u-form-item>
			<u-form-item label="耕作地点" label-width="200"><u-input v-model="form.work_address" /></u-form-item>
			<u-form-item label="身份证国徽面" label-width="200">
				<u-upload :maxCount="maxCount" :showProgress="false"
					@on-uploaded="uploadSuccess" @on-remove="uploadRemove"
					:action="`${$BASE_URL}/api/common/upload`" :header="{token: token}"
					width="138" height="138">
				</u-upload>
			</u-form-item>
			<u-form-item label="身份证人像面" label-width="200">
				<u-upload :maxCount="maxCount" :showProgress="false"
					@on-uploaded="uploadSuccess2" @on-remove="uploadRemove2"
					:action="`${$BASE_URL}/api/common/upload`" :header="{token: token}"
					width="138" height="138" >
				</u-upload>
			</u-form-item>
		</u-form>
		<button class="submitBtn" @click="submit">提交</button>
		<!-- 登录提示 -->
		<shopro-auth-modal></shopro-auth-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				maxCount:1,
				token: uni.getStorageSync('token'),
				form: {
					address:'',
					address_desc: '',
					name: '',
					phone: '',
					type:'',
					idcard_gh_image:'',
					idcard_rx_image:'',
					work_address:''
				},
				showAddress:false,
				typeList: [
					{
						name: '个人',
						value:1,
						disabled: false
					},
					{
						name: '单位',
						value:2,
						disabled: false,
					}
				],
				type:'',
			}
		},
		watch:{
			type(){
				if(this.type =='个人'){
					this.form.type =1;
				}else if(this.type=='单位'){
					this.form.type= 2;
				}
			}
		},
	
		onShow() {
			this.nhApplyData();
		},
		methods: {
			nhApplyData(){
				var _this = this;
				_this.$http('apply.nhApplyData',{}).then(res=>{
					if(res.code !=1){
						uni.showModal({
							title:res.msg,
							success(){
								uni.navigateTo({
									url:"/pages/index/dating"
								})
							}
						})
					}else{
						
					}
				})
			},
			//提交
			submit(){
				var _this = this;
				_this.$http('apply.nhApplySubmit',_this.form).then(res=>{
					if(res.code == 1){
						uni.showToast({
							title:'提交成功',
							icon:'none'
						})
						uni.navigateTo({
							url:"/pages/index/dating"
						})
					}else{
						uni.showToast({
							title:"提交失败",
							icon:'none',
						})
					}
				})
			},
			addressSelect(e){
				this.form.address = e.province.label+e.city.label+e.area.label;
			},
			// 上传图片成功
			uploadSuccess(e) {
				this.imgList = [];
				e.forEach(item => {
					this.form.idcard_gh_image= item.response.data.url;
				});
			},
			// 移除图片
			uploadRemove(index) {
				this.form.idcard_gh_image = '';
			},
			// 上传图片成功
			uploadSuccess2(e) {
				this.imgList = [];
				e.forEach(item => {
					this.form.idcard_rx_image= item.response.data.url;
				});
			},
			// 移除图片
			uploadRemove2(index) {
				this.form.idcard_rx_image = '';
			},
		}
	}
</script>

<style>
	page{
		
		background-color: #fff;
	}
	.box{
		width: 90%;
		margin: 30rpx auto;
	}
	.submitBtn{
		width: 90%;
		background-color: #03A9F4;
		color: #fff;
	}
</style>
